package com.yangchuang.openpicture.communication;

import lombok.Getter;

import java.io.Serial;
import java.io.Serializable;


@Getter
public class ResponseMessage<T> implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    private int code;
    private String message;
    private T data;

    private ResponseMessage(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResponseMessage<T> success(T data) {
        return new ResponseMessage<>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }

    public static <T> ResponseMessage<T> success(T data, String customMsg) {
        return new ResponseMessage<>(ResultCode.SUCCESS.getCode(), customMsg, data);
    }


    public static <T> ResponseMessage<T> fail(ResultCode resultCode) {
        return new ResponseMessage<>(resultCode.getCode(), resultCode.getMessage(), null);
    }

    public static <T> ResponseMessage<T> fail(int code, String message) {
        return new ResponseMessage<>(code, message, null);
    }


}

